﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media.Imaging;

namespace DrawTools.Common
{
    public class StringToIconConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return null;
            var val = value.ToString();
            if (val.StartsWith("/"))
            {
                val = val.Replace("/", "\\");
            }
            else if (val.EndsWith("\\"))
            {
            }
            else
            {
                val = "\\" + val;
            }
            var path = System.IO.Directory.GetCurrentDirectory() + val;
            return new BitmapImage(new Uri(path, UriKind.Absolute));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
